import tushare as ts

from pymongo import MongoClient
import json

client = MongoClient('mongodb://localhost:27017/')
df = ts.get_stock_basics()
df = df.reset_index()
df.rename(columns=({'code': '_id'}), inplace=True)

stocks = client.stocks
stocks.stock_basics.drop()
stocks.stock_basics.insert_many(json.loads(df.to_json(orient='records')))

print('Success')
